package org.example.helloworld.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.example.helloworld.entity.Notice;
import org.example.helloworld.entity.User;
import org.example.helloworld.mapper.UserMapper;
import org.example.helloworld.service.IUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 业主 服务实现类
 * </p>
 *
 * @author author
 * @since 2024-07-06
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public boolean updateById(User user) {
        return userMapper.updateById(user) > 0;
    }


    public IPage<User> getUserList(Page<User> page, String search) {
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        if (search != null && !search.isEmpty()) {
            queryWrapper.lambda().like(User::getUsername, search)
                    .or().like(User::getRealname, search)
                    .or().like(User::getPhone, search);
        }
        return this.page(page, queryWrapper);
    }
}
